/* 
 * ---------------------------------------------------------------
 * This is a program to see if you got a prize. You can use and 
 * modify it as you wish, but this cannot be use in any kind of 
 * bussiness ways. If we meet some day, and you think this program
 * is worth, you can buy me a cola in return.	 	     Heron
 * 					  <v6510young88@gmail.com>
 * ---------------------------------------------------------------
 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int First_num[3],Second_num[3],isEnd_S[3]={0},isMatch_S[3]={0},insert;
void whatprize_S(int matches);
int getPrize=0;
int main(int argc,char **argv){
	//argument setting
	if(argc!=3){
		printf("Usage: ./prize <award_list.txt> <wait for checking text>\n");
		return 0;
	}

	//input
	int i,j;
	freopen(argv[1],"r",stdin);
	FILE *fin=fopen(argv[2],"r");
	fscanf(fin,"%d",&insert);
	for(i=0;i<3;i++)	scanf("%d",&First_num[i]);
	for(i=0;i<3;i++)	scanf("%d",&Second_num[i]);
	for(i=0;i<3;i++)	isEnd_S[i]=0;
	for(i=0;i<3;i++)	isMatch_S[i]=0;

	//print for check
	//printf("insert num >> %d\n\n",insert);
	for(i=0;i<3;i++)	printf("First_num[%d] : %d\n",i+1,First_num[i]);
	for(i=0;i<3;i++)	printf("Second_num[%d] : %d\n",i+1,Second_num[i]);
	printf("\n");
	//got prize or not
	//
	//Second_num do first
	for(i=3;i<=8;i++){
		for(j=0;j<3;j++){
			if(isEnd_S[j])	continue;
			int get=pow(10,i);
			if((int)insert%get != (int)Second_num[j]%get){
				if(isMatch_S[j])	{whatprize_S(i-1);return 0;}
				isEnd_S[j]=1;
			}
			else if(i==8)	{whatprize_S(i);return 0;}
			else	isMatch_S[j]=1;
		}
	}

	//get the Special Pirze or not
	for(i=0;i<3;i++)
		if(insert==First_num[i]){
			printf("Suprise!!!!!!!!\nYOU GOT THE SPECIAL PRIZE!!\n $ 2,000,000 !!\n");
			system("go 0.wav");//play sound
			getPrize=1;
		}
	//else
	if(!getPrize)
		printf("sorry...no prize!\n");
	//end
	return 0;
}
void whatprize_S(int matches){
	switch(matches){
		case 3:	printf("You won the SIXTH PRIZE !! $200\n");
			system("go 6.wav");//play sound
			break;
		case 4:	printf("You won the FIFTH PRIZE !! $1,000\n");
			system("go 5.wav");//play sound
			break;
		case 5:	printf("You won the FORTH PRIZE !! $4,000\n");
			system("go 4.wav");//play sound
			break;
		case 6:	printf("You won the THIRD PRIZE !! $10,000\n");
			system("go 3.wav");//play sound
			break;
		case 7:	printf("You won the Seond PRIZE !! $40,000\n");
			system("go 2.wav");//play sound
			break;
		case 8:	printf("You won the First PRIZE !! $200,000\nWow Wow...Congratulations~!\n");
			system("go 1.wav");//play sound
			break;
	}
	getPrize=1;
}
